//
//  InstructionViewController.m
//  JiongTu
//
//  Created by 杨璟 on 16/3/29.
//  Copyright © 2016年 YSKJ. All rights reserved.
//

#import "InstructionViewController.h"

#import "JTButton.h"

@interface InstructionViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet JTButton *passBtn;
@property (weak, nonatomic) IBOutlet JTButton *driverBtn;

@property (weak, nonatomic) IBOutlet UIWebView *insWebView;

@end

@implementation InstructionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addObserver:self forKeyPath:@"self.passBtn.selected" options:NSKeyValueObservingOptionNew context:nil];
    
    self.passBtn.selected = YES;
    
    self.passBtn.layer.borderWidth = 0.5;
    self.driverBtn.layer.borderWidth = 0.5;
    
    self.passBtn.layer.borderColor = [[UIColor colorWithRed:122/255.0 green:152/255.0 blue:51/255.0 alpha:1.0] CGColor];
    self.driverBtn.layer.borderColor = [[UIColor colorWithRed:122/255.0 green:152/255.0 blue:51/255.0 alpha:1.0] CGColor];
}

- (void)dealloc {
    [self removeObserver:self forKeyPath:@"self.passBtn.selected"];
}

- (IBAction)passBtnClick:(id)sender {
    if (!self.passBtn.isSelected) {
        self.passBtn.selected = !self.passBtn.isSelected;
        self.driverBtn.selected = !self.driverBtn.isSelected;
    }
}

- (IBAction)driverBtnClick:(id)sender {
    if (!self.driverBtn.isSelected) {
        self.driverBtn.selected = !self.driverBtn.isSelected;
        self.passBtn.selected = !self.passBtn.isSelected;
    }
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
    if ([change[@"new"] isEqualToNumber:@1]) {
//        NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Instrucation_pass" ofType:@"html"];
//        NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
//        [self.insWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Instrucation_pass" ofType:@"html"];
        NSURL *url = [NSURL fileURLWithPath:filePath];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [self.insWebView loadRequest:request];
    } else {
//        NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Instrucation_driver" ofType:@"html"];
//        NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
//        [self.insWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Instrucation_driver" ofType:@"html"];
        NSURL *url = [NSURL fileURLWithPath:filePath];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [self.insWebView loadRequest:request];
    }
}

@end
